package com.cskaoyan.app.wxcontroller;

import com.cskaoyan.app.bean.bo.WxCommentListBO;
import com.cskaoyan.app.bean.bo.WxCommentPostBO;
import com.cskaoyan.app.bean.common.BaseRespVo;
import com.cskaoyan.app.bean.common.CommonData;
import com.cskaoyan.app.bean.po.MarketCategory;
import com.cskaoyan.app.bean.po.MarketComment;
import com.cskaoyan.app.bean.po.MarketOrder;
import com.cskaoyan.app.bean.vo.WxCommentCountVO;
import com.cskaoyan.app.wxservice.WeChatCommentService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author Shuuka
 * @email 1712430536@qq.com
 * @date 2023/1/2 9:50
 */
@RestController
@RequestMapping("wx/comment")
public class WeChatCommentController {

    @Autowired
    WeChatCommentService weChatCommentService;

    @GetMapping("count")
    public BaseRespVo<Object> count(Integer valueId,Integer type){
        WxCommentCountVO wxCommentCountVO = weChatCommentService.count(valueId,type);
        return BaseRespVo.ok(wxCommentCountVO);
    }

    @GetMapping("list")
    public BaseRespVo<Object> list(WxCommentListBO wxCommentListBO){
        CommonData<MarketComment> data = weChatCommentService.list(wxCommentListBO);
        return BaseRespVo.ok(data);
    }

    @PostMapping("post")
    public BaseRespVo<Object> post(@RequestBody @Validated WxCommentPostBO wxCommentPostBO){
        Subject subject = SecurityUtils.getSubject();
        Integer userid = (Integer) subject.getSession().getAttribute("userid");
        if(userid == null){
            return BaseRespVo.unAuthed();
        }
        MarketComment marketComment = weChatCommentService.post(wxCommentPostBO,userid);
        return BaseRespVo.ok(marketComment);
    }

}
